(async function() { const chartData = { datasets: [{ label: 'Air Temperature', data: [{"x":0,"y":-11.3},{"x":-1,"y":-10.8},{"x":-2,"y":-10.2},{"x":-3,"y":-9.9},{"x":-4,"y":-10.6},{"x":-5,"y":-10.1},{"x":-6,"y":-9.2},{"x":-7,"y":-8.3},{"x":-8,"y":-7.6},{"x":-9,"y":-7.1},{"x":-10,"y":-7.1},{"x":-11,"y":-7.6},{"x":-12,"y":-8},{"x":-13,"y":-8.4},{"x":-14,"y":-9.2},{"x":-15,"y":-9.9},{"x":-16,"y":-10.5},{"x":-17,"y":-11.3},{"x":-18,"y":-11.8},{"x":-19,"y":-11.5},{"x":-20,"y":-11.9},{"x":-21,"y":-12.2},{"x":-22,"y":-12.6},{"x":-23,"y":-11.9}], backgroundColor: '#D5202A' }] } ctx = document.getElementById('airTemp').getContext('2d'); chart = new Chart(ctx, { type: 'scatter', data: chartData, showLine: true, options: { scales: { x: { title: { display: true, text: 'Hours', font: { size: 16 }, } }, y: { title: { display: true, text: '°C', font: { size: 16 }, } } } } }) if(chartData.datasets[0].data.length === 0) { const width = chart.width const height = chart.height const chart_ctx = chart.ctx; var fontSize = (height / 114).toFixed(2); chart_ctx.font = fontSize + "em sans-serif"; chart_ctx.fillStyle = "red"; chart_ctx.textBaseline = "middle"; var text = 'No Data', textX = Math.round((width - ctx.measureText(text).width) / 2), textY = height / 2; ctx.fillText(text, textX, textY); } })();